package com.villaday.idf.adapter;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Paint;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.villaday.idf.R;
import com.villaday.idf.base.AbsRecyclerViewAdapter;
import com.villaday.idf.base.OnAdapterCallbackListener;
import com.villaday.idf.custom.foldtext.FoldTextView;
import com.villaday.idf.model.PresellEntity;
import com.villaday.idf.model.RefreshtokenEntity;
import com.villaday.idf.util.PhoneUtil;
import com.villaday.idf.util.SharedPreferencesUtil;

import java.math.BigDecimal;

/**
 * 首页动态列表
 */

public class HomeListSaleAdapter extends AbsRecyclerViewAdapter<PresellEntity.BodyEntity.PresellListEntity.ListEntity> {
    private OnAdapterCallbackListener onAdapterCallbackListener;
    private View.OnClickListener onClickListener;
    private final String roleType;

    public HomeListSaleAdapter(Context context, OnAdapterCallbackListener onAdapterCallbackListener, View.OnClickListener onClickListener) {
        super(context, R.layout.item_home_sale, R.layout.item_page_loading,
                R.layout.item_page_bottom);
        this.onAdapterCallbackListener = onAdapterCallbackListener;
        this.onClickListener = onClickListener;
        RefreshtokenEntity.BodyBean roleInfo =
                SharedPreferencesUtil.getRoleInfo(context);
        roleType = roleInfo.getMember().getType();

    }

    @Override
    public int getItemType(PresellEntity.BodyEntity.PresellListEntity.ListEntity d) {
        return d.getMyType();
    }

    @Override
    public void onBindHolder(AbsRecyclerViewAdapter.RecyclerViewHolder holder, PresellEntity.BodyEntity.PresellListEntity.ListEntity d, int position) {
        switch (d.getMyType()) {

            case 0: {//

                holder.bindTextView(R.id.tv_remai, d.getHouse().getAddress())
                        .setViewVisible(R.id.tv_remai, (TextUtils.isEmpty(d.getHouse().getAddress() )?View.INVISIBLE:View.VISIBLE) )


                        .bindSimpleDraweeView(R.id.sdv, d.getImageURL()+"")
                        .bindTextView(R.id.tv_description, d.getHouse().getRoomNum() + "室" + d.getHouse().getHallNum() + "厅" + d.getHouse().getBedNum() + "床" + "  |  " + d.getHouse().getAcreage() + "㎡" + "  |  " + (d.getHouse().getHouseType()==3 ? "可玩" : "宜住") + d.getHouse().getPeopleNum() + "人")
                        .bindTextView(R.id.tv_addr, "截止日期：" + d.getExpiredDate())
                        .bindTextView(R.id.tv_name, d.getName())
                        .bindTextView(R.id.tv_chaodi, d.getTag())

                        .bindTextView(R.id.tv_zhuanNum, PhoneUtil.handleBalance(d.getBrokerAge() / 100.0 + "", 2))

                        .bindTextViewWithHtml(R.id.tv_price, "&yen;" + (d.getCurrentPrice() == 0 ? "0.00" : PhoneUtil.handleBalance(d.getCurrentPrice() / 100.0 + "", 2)))
/*
                        .bindTextView(R.id.tv_zhe, d.getOriginalPrice()==0?"0.0折":new BigDecimal(((double) d.getCurrentPrice() * 10/ (double)d.getOriginalPrice()) ).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue() + "折")
*/
/*
                        .bindTextView(R.id.tv_zhe, d.getOriginalPrice()==0?"0.0折":(((double) d.getCurrentPrice() * 10/ (double)d.getOriginalPrice())+"").substring(0,3)+ "折")
*/
                        .bindTextView(R.id.tv_zhe, TextUtils.isEmpty(d.getDiscount()) || (Double.parseDouble(d.getDiscount()) == 0.0) ? "" : d.getDiscount() + "折")

                        .bindTextViewWithHtml(R.id.tv_delete, "&yen;" + (d.getOriginalPrice() == 0 ? "0.00" : PhoneUtil.handleBalance(d.getOriginalPrice() / 100.0 + "", 2)))
                        .bindTextViewWithHtml(R.id.textView3, "&yen;")

                        .setClickListenerAndTag(R.id.tv_tuiguang, onClickListener, position)
                        .setClickListenerAndTag(R.id.tv_lijiBuy, onClickListener, position)

                        .setViewVisible(R.id.tv_lijiBuy, "0".equals(roleType) ? View.VISIBLE : View.GONE)

                        .setViewVisible(R.id.tv_zhuan, "0".equals(roleType) ? View.GONE : View.VISIBLE)
                        .setViewVisible(R.id.textView3, "0".equals(roleType) ? View.GONE : View.VISIBLE)
                        .setViewVisible(R.id.tv_zhuanNum, "0".equals(roleType) ? View.GONE : View.VISIBLE)
                        .setViewVisible(R.id.tv_tuiguang, "0".equals(roleType) ? View.GONE : View.VISIBLE)
                        .setViewVisible(R.id.tv_description, d.isHasHouse()?View.VISIBLE : View.GONE)
                        .setViewVisible(R.id.tv_remai, d.isHasHouse()?View.VISIBLE : View.GONE)

                        .setViewVisible(R.id.tv_chaodi, TextUtils.isEmpty(d.getTag())?View.GONE : View.VISIBLE);

                TextView view = (TextView) holder.getView(R.id.tv_delete);
//添加删除线
                view.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
               /* holder.setClickListenerAndTag(R.id.img_collect, onClickListener, position)
                        .setClickListenerAndTag(R.id.tv_erweima, onClickListener, position)
                        .setClickListenerAndTag(R.id.tv_share1, onClickListener, position);
                FoldTextView ftv = (FoldTextView) holder.getView(R.id.ftv);
                ftv.setText("111111123111111123阿斯顿发阿斯顿发送到大111111123阿斯顿发阿斯顿发送到大111111123阿斯顿发阿斯顿发送到大111111123阿斯顿发阿斯顿发送到大111111123阿斯顿发阿斯顿发送到大阿斯顿发阿斯顿发送到大。厦法定阿萨【德法师打发斯蒂芬撒地】方阿萨德法师打发斯问问蒂芬撒地方阿萨德法师打发斯蒂。芬撒地方发送到发送到发送到发送到发送到发送，到发送到发送到发送到，发送111111123阿斯顿发阿斯顿发送到大。厦法定阿萨【德法师打发斯蒂芬撒地】方阿萨德法师打发斯问问蒂芬撒地方阿萨德法师打发斯蒂。芬撒地方发送到发送到发送到发送到发送到发送，到发送到发送到发送到，发送");
*/
                View view1 = holder.getView(R.id.tv_zhe);
                if (TextUtils.isEmpty(d.getDiscount()) || (Double.parseDouble(d.getDiscount()) == 0.0)) {
                    view1.setBackgroundColor(Color.parseColor("#00000000"));
                } else {
                    view1.setBackgroundColor(Color.parseColor("#fcebeb"));

                }
            }
            break;

            case 1: {
                onAdapterCallbackListener.onCallback();
            }
            break;


        }
    }
}
